package com.wwr.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ResourceBundle;

@Configuration
public class CusIntercepter implements WebMvcConfigurer {

    @Autowired
    private BaseInterceptor baseInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //告知拦截器：/static/admin/** 与 /static/user/** 不需要拦截 （配置的是 路径）
        String[] excludes = new String[]{"/static/**"};
        registry.addInterceptor(baseInterceptor).addPathPatterns("/**").excludePathPatterns(excludes);
    }

    /**
     * 添加静态文件，外部可以直接访问
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //获取配置文件
//        ResourceBundle resource = ResourceBundle.getBundle("config");
//        String filePath = resource.getString("filePath");
//        registry.addResourceHandler("/**").addResourceLocations("file:"+filePath);//添加文件访问路径
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");//设置静态资源不被拦截
    }
}
